<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Admincms extends CI_Controller {

function __construct()
    {
        parent::__construct();
    	$this->load->library('session');
		$this->load->helper('url');
		$this->load->model("adminmod");
    	//$this->load->model("cmsmodel");
	}
	

		
		
	
 function page_newcostumer()
	{
		if($this->session->userdata("user")==false)
		{
		 		 $this->load->view("login");
			
		}else
			{
			$iduser=$session=$this->session->userdata("id");
			$nameuser=$this->session->userdata("user");
			$data=array('userid'=>$iduser,"nameuser"=>$nameuser);
			$this->load->view("newcostumer",$data);
				
		}


	}//adimin_hotel
	

	

	
function  loginout()
	{
		$info=array("id"=>"","user"=>"");
		$this->session->unset_userdata($info);
		$this->load->view("login");
	}
	
	
//############## function for enregistrement costumer information###################
/*
	function addinfor_hotel()
	{
		if($this->session->userdata("user")==false)
		{
		 		 $this->load->view("login");
			
		}else{
				
				 $idhotel=$this->input->get_post("idhotel"); 
				 $hotelname=$this->input->get_post("h_hotelname"); 
				 $adress=$this->input->get_post("h_adress"); 
				 $email=$this->input->get_post("h_email"); 
				 $description=$this->input->get_post("h_description"); 
				 $description_en=$this->input->get_post("h_description_en"); 
				 $email=	$this->input->get_post("h_email"); 
				 $ssh=$this->input->get_post("h_link_pdf"); 
				 $fax=$this->input->get_post("h_fax"); 	
				 $map=	$this->input->get_post("h_map"); 
				 $tel_local=$this->input->get_post("h_tel_local"); 	
				 $website=$this->input->get_post("h_website"); 
				 $level=$this->input->get_post("h_level"); 
				 $postion=$this->input->get_post("h_position");
				 $postion_arr=explode(",",$postion);
				 
				 $data=array(
				 "hotelname"=>$hotelname, 
				 "adress"=>$adress, 
				 "email"=>$email,
				 "link_pdf"=>$ssh, 
				 "description"=>$description ,
				 "desc_en"=>$description_en, 
				 "fax"=>$fax ,	
				 "map"=>$map ,
				 "tel_local"=>$tel_local, 	
				 "website"=>$website ,
				 "level"=>$level,
				 "axe_x"=>$postion_arr[0],
				 "axe_y"=>$postion_arr[1]
				 );
				 $idinsert=$this->cmsmodel-> insertetemplate("hotel",$data);
				 $error="hotel information is saved!";
				
				 $this->page_admin_hotel($idinsert,$error);
		
		}
		}
*/		
function adminmenu()
{
		if($this->session->userdata("user")==false)
		{
		 		 $this->load->view("admin/login");
			
		}else{
	$listdept=$this->adminmod->getlistdept();
	$listcats=$this->adminmod->getlistcats();
	$listproduct=$this->adminmod->getlistproduct();
	$listlocaux=$this->adminmod->getlistlocaux();
	$data=array("listdept"=>$listdept,"listcats"=>$listcats,"listproduct"=>$listproduct,"listlocaux"=>$listlocaux);
	$this->load->view("admin/adminmenu",$data);
		}
}	
	
//------------------------

/**     add page     **/	
function pageaddproduct()
{
if($this->session->userdata("user")==false)
{
		 		 $this->load->view("admin/login");
			
}else{
	$listcats=$this->adminmod->getlistcats();
	$data=array("listcats"=>$listcats);
	$this->load->view("admin/addproduct",$data);
}
}	

function pageadddept()
{
if($this->session->userdata("user")==false)
{
$this->load->view("admin/login");
			
}else{
	$this->load->view("admin/adddept");
}
}

function pageaddcats()
{
	if($this->session->userdata("user")==false)
{
		 		 $this->load->view("admin/login");
			
}else{
	$listdept=$this->adminmod->getlistdept();
	$data=array("listdept"=>$listdept);
	$this->load->view("admin/addcats",$data);
}
}

function pageaddlocaux()
{
if($this->session->userdata("user")==false)
{
	 $this->load->view("admin/login");
			
}else{
	$this->load->view("admin/addlocaux");

}
}


//____________add action________________________


function actadddept()
{
if($this->session->userdata("user")==false)
{
		 		 $this->load->view("admin/login");
			
}else{
	$deptname_en=$this->input->get_post("deptname_en"); 
	$deptname_fr=$this->input->get_post("deptname_fr"); 
	$data=array("deptname_en"=>$deptname_en,"deptname_fr"=>$deptname_fr);
	$this->adminmod->insertetemplate("department",$data);
	redirect(base_url()."admincms/pageadddept");
}
}


function actaddcats()
{
	if($this->session->userdata("user")==false)
{
		 		 $this->load->view("admin/login");
			
}else{
	$fk_iddepartment=$this->input->get_post("fk_iddepartment"); 
	$catname_en=$this->input->get_post("catname_en"); 
	$catname_fr=$this->input->get_post("catname_fr"); 
	$description_en=$this->input->get_post("description_en"); 
	$description_fr=$this->input->get_post("description_fr"); 
	$image=$this->input->get_post("image");
	$video=$this->input->get_post("video");
	$data=array("catname_en"=>$catname_en,"catname_fr"=>$catname_fr,"description_en"=>$description_en,
	"description_fr"=>$description_fr,"image"=>$image,"video"=>$video,"fk_iddepartment"=>$fk_iddepartment);
	$this->adminmod->insertetemplate("category",$data);
	redirect(base_url()."admincms/pageaddcats");
}	
}

function actaddproducts()
{
	if($this->session->userdata("user")==false)
{
		 		 $this->load->view("admin/login");
			
}else{
	$fk_idcategory=$this->input->get_post("fk_idcategory"); 
	$productname_en=$this->input->get_post("productname_en"); 
	$productname_fr=$this->input->get_post("productname_fr"); 
	$description_fr=$this->input->get_post("description_fr"); 
	$description_en=$this->input->get_post("description_en");
	$sildershow=$this->input->get_post("sildershow");
	$video=$this->input->get_post("video");
	$data=array("fk_idcategory"=>$fk_idcategory,"productname_en"=>$productname_en,"productname_fr"=>$productname_fr,
	"description_en"=>$description_en,"description_fr"=>$description_fr,"sildershow"=>$sildershow,"video"=>$video);
	$this->adminmod->insertetemplate("product",$data);
	redirect(base_url()."admincms/pageaddproduct");
}
}



function actaddlocaux()
{
	if($this->session->userdata("user")==false)
{
		 		 $this->load->view("admin/login");
			
}else{
	$name=$this->input->get_post("name"); 
	$code=$this->input->get_post("code"); 
	$address=$this->input->get_post("address"); 
	$ville=$this->input->get_post("ville"); 
	$zip=$this->input->get_post("zip"); 
	$tel=$this->input->get_post("tel"); 
	$fax=$this->input->get_post("fax"); 
	$details_en=$this->input->get_post("details_en"); 
	$details_fr=$this->input->get_post("details_fr"); 
	$maplink=$this->input->get_post("maplink"); 
	$data=array("name"=>$name,"code"=>$code,"address"=>$address,"ville"=>$ville,"zip"=>$zip,"tel"=>$tel,"fax"=>$fax,"details_en"=>$details_en,"details_fr"=>$details_fr,"maplink"=>$maplink);
	$this->adminmod->insertetemplate("restolocal",$data);
	redirect(base_url()."admincms/pageaddlocaux");
}	
}







//######################## edit###########################

function pageeditdept()
{
	if($this->session->userdata("user")==false)
{
		 		 $this->load->view("admin/login");
			
}else{	
	$iddepartment=$this->input->get_post("iddepartment"); 
	$departmentinfo=$this->adminmod->getlistdeptinfo($iddepartment);
	$data=array("departmentinfo"=>$departmentinfo);
	$this->load->view("admin/editdept",$data);
	
}	
}


function pageeditcats()
{
	if($this->session->userdata("user")==false)
{
		 		 $this->load->view("admin/login");
			
}else{
	$idcategory=$this->input->get_post("idcategory"); 
	$listdept=$this->adminmod->getlistdept();
	$catsinfo=$this->adminmod->getlistcatinfo($idcategory);
	$data=array("listdept"=>$listdept,"catsinfo"=>$catsinfo);
	$this->load->view("admin/editcats",$data);

}
}


function pageeditproduct()
{
	if($this->session->userdata("user")==false)
{
		 		 $this->load->view("admin/login");
			
}else{
	
	$idproduct=$this->input->get_post("idproduct");
	$listcats=$this->adminmod->getlistcats();
	$product=$this->adminmod->getlistporductinfo($idproduct);
	$data=array("listcats"=>$listcats,"productinfo"=>$product);
	$this->load->view("admin/editproduct",$data);
}
}


function pageeditlocaux()
{
	if($this->session->userdata("user")==false)
{
		 		 $this->load->view("admin/login");
			
}else{
	$idlocal=$this->input->get_post("idlocal");
	$loacauxinfo=$this->adminmod->getlistlocauxinfo($idlocal);
	$data=array("loacauxinfo"=>$loacauxinfo);
	$this->load->view("admin/editlocaux",$data);
}
}




// action 

function acteditdept()
{
	if($this->session->userdata("user")==false)
{
		 		 $this->load->view("admin/login");
			
}else{
	
	$iddepartment=$this->input->get_post("iddepartment");
	$deptname_en=$this->input->get_post("deptname_en"); 
	$deptname_fr=$this->input->get_post("deptname_fr"); 
	$data=array("deptname_en"=>$deptname_en,"deptname_fr"=>$deptname_fr);
	$this->adminmod->updatetemplate("department",$data,"iddepartment=$iddepartment");
	redirect(base_url()."admincms/adminmenu");
}	
}

function acteditcats()
{
	
	if($this->session->userdata("user")==false)
{
		 		 $this->load->view("admin/login");
			
}else{
	$idcategory=$this->input->get_post("idcategory"); 
	$fk_iddepartment=$this->input->get_post("fk_iddepartment"); 
	$catname_en=$this->input->get_post("catname_en"); 
	$catname_fr=$this->input->get_post("catname_fr"); 
	$description_en=$this->input->get_post("description_en"); 
	$description_fr=$this->input->get_post("description_fr"); 
	$image=$this->input->get_post("image");
	$video=$this->input->get_post("video");
	$data=array("catname_en"=>$catname_en,"catname_fr"=>$catname_fr,"description_en"=>$description_en,
	"description_fr"=>$description_fr,"image"=>$image,"video"=>$video,"fk_iddepartment"=>$fk_iddepartment);
	$this->adminmod->updatetemplate("category",$data,"idcategory=$idcategory");
	redirect(base_url()."admincms/adminmenu");
}
}


function acteditproducts()
{
	if($this->session->userdata("user")==false)
{
		 		 $this->load->view("admin/login");
			
}else{
	$idproduct=$this->input->get_post("idproduct");
	$fk_idcategory=$this->input->get_post("fk_idcategory"); 
	$productname_en=$this->input->get_post("productname_en"); 
	$productname_fr=$this->input->get_post("productname_fr"); 
	$description_fr=$this->input->get_post("description_fr"); 
	$description_en=$this->input->get_post("description_en");
	$sildershow=$this->input->get_post("sildershow");
	$video=$this->input->get_post("video");
	$data=array("fk_idcategory"=>$fk_idcategory,"productname_en"=>$productname_en,"productname_fr"=>$productname_fr,
	"description_en"=>$description_en,"description_fr"=>$description_fr,"sildershow"=>$sildershow,"video"=>$video);
	$this->adminmod->updatetemplate("product",$data,"idproduct=$idproduct");
	redirect(base_url()."admincms/adminmenu");
}
}



function acteditlocaux()
{
	if($this->session->userdata("user")==false)
{
		 		 $this->load->view("admin/login");
			
}else{
	$idlocal=$this->input->get_post("idlocal"); 
	$name=$this->input->get_post("name"); 
	$code=$this->input->get_post("code"); 
	$address=$this->input->get_post("address"); 
	$ville=$this->input->get_post("ville"); 
	$zip=$this->input->get_post("zip"); 
	$tel=$this->input->get_post("tel"); 
	$fax=$this->input->get_post("fax"); 
	$details_en=$this->input->get_post("details_en"); 
	$details_fr=$this->input->get_post("details_fr"); 
	$maplink=$this->input->get_post("maplink"); 
	$data=array("name"=>$name,"code"=>$code,"address"=>$address,"ville"=>$ville,"zip"=>$zip,"tel"=>$tel,"fax"=>$fax,"details_en"=>$details_en,"details_fr"=>$details_fr,"maplink"=>$maplink);
	$this->adminmod->updatetemplate("restolocal",$data,"idlocal=$idlocal");
	redirect(base_url()."admincms/adminmenu");
}
}



/************************************  for local part **************************************
 * 
 * 
 * 
 */
function pagelocaldept()
	{
		if($this->session->userdata("user")==false)
{
		 		 $this->load->view("admin/login");
			
}else{
		
		$idlocal=$this->input->get_post("idlocal");
		$listlocaldept=$this->adminmod->getlistlocaldept($idlocal);
		$listdeptnotselected=$this->adminmod->getlistdeptnoselected($idlocal);
		$data=array("listlocaldept"=>$listlocaldept,"listdeptnotselected"=>$listdeptnotselected,"idlocal"=>$idlocal);
		$this->load->view("admin/local/addloaldept",$data);
}		
		
	}

	
function  pagelocalcat()
	{
		if($this->session->userdata("user")==false)
{
		 		 $this->load->view("admin/login");
			
}else{
		
		$idlocal=$this->input->get_post("idlocal");
		$listcats=$this->adminmod->getlistcatsforlocalcat($idlocal);
		$listperiod=$this->adminmod->getlistperiod();
		$listlocatsexit=$this->adminmod->getlocalcatexit($idlocal);
		$data=array("idlocal"=>$idlocal,"listcats"=>$listcats,"listperiod"=>$listperiod,"listlocatsexit"=>$listlocatsexit);
		$this->load->view("admin/local/addloalcat",$data);
}		
		
	}	
	

function pagelocalproduct()
	{
		
		if($this->session->userdata("user")==false)
{
		 		 $this->load->view("admin/login");
			
}else{		
		$idlocal=$this->input->get_post("idlocal");
		$idlocalcat=$this->input->get_post("idlocalcat");
		$getlistproductnoselectbylcat=$this->adminmod->getlistproductnoselectbylcat($idlocalcat);
		$getlistproductselection=$this->adminmod->getlistproductselection($idlocalcat);
		$data=array("idlocal"=>$idlocal,"idlocalcat"=>$idlocalcat,"getlistproductnoselectbylcat"=>$getlistproductnoselectbylcat,"getlistproductselection"=>$getlistproductselection);
		$this->load->view("admin/local/addloalproduct",$data);
}	
}
	
	
	
//add 
function actaddlocaldept()
	{
		

		if($this->session->userdata("user")==false)
{
		 		 $this->load->view("admin/login");
			
}else{		
		$fk_depart_id=$this->input->get_post("fk_depart_id");
		$fk_local_id=$this->input->get_post("fk_local_id");
		$data=array("fk_depart_id"=>$fk_depart_id,"fk_local_id"=>$fk_local_id);
		$idinsert=$this->adminmod->insertetemplate("localdepartment",$data);
		redirect(base_url()."admincms/adminmenu");
}	
}



	

function actaddlocalcat()
	{
		
		if($this->session->userdata("user")==false)
{
		 		 $this->load->view("admin/login");
			
}else{		
		$localdepartment_idlocaldepartment=$this->input->get_post("localdepartment_idlocaldepartment");
		$fk_local_id=$this->input->get_post("fk_local_id");
		$fk_depart_id=$this->input->get_post("fk_depart_id");
		$fk_idcategory=$this->input->get_post("fk_idcategory");
		$period_idperiod=$this->input->get_post("period_idperiod");
		
		
		$data=array("localdepartment_idlocaldepartment"=>$localdepartment_idlocaldepartment,
		"fk_local_id"=>$fk_local_id,"fk_depart_id"=>$fk_depart_id,"fk_idcategory"=>$fk_idcategory,
		"period_idperiod"=>$period_idperiod);
		$idinsert=$this->adminmod->insertetemplate("localcat",$data);
		redirect(base_url()."admincms/adminmenu");
}	
}
	

	
function actaddlocalproduct()
	{
		
		if($this->session->userdata("user")==false)
{
		 		 $this->load->view("admin/login");
			
}else{		
		$fk_idcategory=$this->input->get_post("fk_idcategory");
		$localcat_idlocalcats=$this->input->get_post("localcat_idlocalcats");
		$arr_idproduct=$this->input->get_post("idproduct");
		foreach ($arr_idproduct as $aprod){
		$data=array("fk_idcategory"=>$fk_idcategory,"localcat_idlocalcats"=>$localcat_idlocalcats,"idproduct"=>$aprod);
		$idinsert=$this->adminmod->insertetemplate("localproduct",$data);
		}
		redirect(base_url()."admincms/adminmenu");
}	
}
	
	

	
// -----------edit-------	

	
function acteditlocaldept()
{
		if($this->session->userdata("user")==false)
{
		$this->load->view("admin/login");
			
}else{		
		$idlocaldepartment=$this->input->get_post("idlocaldepartment");
		$description_en=$this->input->get_post("description_en");
		$description_fr=$this->input->get_post("descriptions_fr");
		$order=$this->input->get_post("order");
		$data=array("description_en"=>$description_en,"descriptions_fr"=>$description_fr,"order"=>$order);
		$idinsert=$this->adminmod->updatetemplate("localdepartment",$data,"idlocaldepartment=$idlocaldepartment");
		redirect(base_url()."admincms/adminmenu");
}	
}	
	
function  acteditlocalcat()
{
	if($this->session->userdata("user")==false)
{
		 		 $this->load->view("admin/login");
			
}else{
	$idlocalcats=$this->input->get_post("idlocalcats");
	$description_en=$this->input->get_post("description_en");
	$description_fr=$this->input->get_post("descriptions_fr");
	$order=$this->input->get_post("order");
	$data=array("description_en"=>$description_en,"description_fr"=>$description_fr,"order"=>$order);
	$idinsert=$this->adminmod->updatetemplate("localcat",$data,"idlocalcats=$idlocalcats");
	redirect(base_url()."admincms/adminmenu");
}
}




function getlocalcatbylc($idlocal)
{
	$listlocalcat=$this->adminmod->getlistlocalcatbylocal($idlocal);
	echo json_encode($listlocalcat);
	
}



//############### end function for enregistrement ##################################	


	
}//class
?>